import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _omit from "lodash/omit";
import { stringify } from 'qs';
import request from 'utils/request';
import { CPAAS_IAM } from 'utils/config';
export function queryMenuTree() {
  return _queryMenuTree.apply(this, arguments);
}

function _queryMenuTree() {
  _queryMenuTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var params,
        _args = arguments;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/menus/tree"), {
              query: params
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryMenuTree.apply(this, arguments);
}

export function createMenuDir() {
  return _createMenuDir.apply(this, arguments);
}

function _createMenuDir() {
  _createMenuDir = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    var params,
        _args2 = arguments;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/v1/menus"), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _createMenuDir.apply(this, arguments);
}

export function saveMenuDir() {
  return _saveMenuDir.apply(this, arguments);
}

function _saveMenuDir() {
  _saveMenuDir = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
    var params,
        _args3 = arguments;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            params = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
            return _context3.abrupt("return", request("".concat(CPAAS_IAM, "/v1/menus/").concat(params.id), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _saveMenuDir.apply(this, arguments);
}

export function deleteMenuTree(_x) {
  return _deleteMenuTree.apply(this, arguments);
}

function _deleteMenuTree() {
  _deleteMenuTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(id) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_IAM, "/v1/menus/").concat(id), {
              method: 'DELETE'
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _deleteMenuTree.apply(this, arguments);
}

export function customMenuImport(_x2, _x3) {
  return _customMenuImport.apply(this, arguments);
}

function _customMenuImport() {
  _customMenuImport = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(organizationId, params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId, "/menus/custom-menu-import"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _customMenuImport.apply(this, arguments);
}

export function queryMenuTreeByOrganizationId(_x4, _x5) {
  return _queryMenuTreeByOrganizationId.apply(this, arguments);
}

function _queryMenuTreeByOrganizationId() {
  _queryMenuTreeByOrganizationId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(organizationId, params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId, "/menus/tree"), {
              query: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _queryMenuTreeByOrganizationId.apply(this, arguments);
}

export function createMenuDirByOrganizationId() {
  return _createMenuDirByOrganizationId.apply(this, arguments);
}

function _createMenuDirByOrganizationId() {
  _createMenuDirByOrganizationId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
    var params,
        organizationId,
        _args7 = arguments;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            params = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
            organizationId = params.organizationId;
            return _context7.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId, "/menus/create"), {
              method: 'POST',
              body: _omit(params, 'organizationId')
            }));

          case 3:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _createMenuDirByOrganizationId.apply(this, arguments);
}

export function checkMenuDirExists() {
  return _checkMenuDirExists.apply(this, arguments);
}

function _checkMenuDirExists() {
  _checkMenuDirExists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
    var params,
        _args8 = arguments;
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            params = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
            return _context8.abrupt("return", request("".concat(CPAAS_IAM, "/v1/menus/check"), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _checkMenuDirExists.apply(this, arguments);
}

export function saveMenuTree(_x6, _x7) {
  return _saveMenuTree.apply(this, arguments);
}

function _saveMenuTree() {
  _saveMenuTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params, level) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request("".concat(CPAAS_IAM, "/v1/menus/tree?").concat(stringify({
              level: level
            })), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _saveMenuTree.apply(this, arguments);
}

export function checkMenuDirExistsByOrganizationId(_x8) {
  return _checkMenuDirExistsByOrganizationId.apply(this, arguments);
}

function _checkMenuDirExistsByOrganizationId() {
  _checkMenuDirExistsByOrganizationId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(organizationId) {
    var customFlag,
        params,
        _args10 = arguments;
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            customFlag = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : true;
            params = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : {};
            return _context10.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId, "/menus/check-duplicate"), {
              method: 'POST',
              body: params,
              query: {
                custom_flag: customFlag
              }
            }));

          case 3:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _checkMenuDirExistsByOrganizationId.apply(this, arguments);
}

export function saveMenuTreeByOrganizationId(_x9, _x10, _x11) {
  return _saveMenuTreeByOrganizationId.apply(this, arguments);
}

function _saveMenuTreeByOrganizationId() {
  _saveMenuTreeByOrganizationId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(organizationId, params, level) {
    var customFlag,
        _args11 = arguments;
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            customFlag = _args11.length > 3 && _args11[3] !== undefined ? _args11[3] : true;
            return _context11.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId, "/menus/tree"), {
              method: 'POST',
              body: params,
              query: {
                level: level,
                custom_flag: customFlag
              }
            }));

          case 2:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _saveMenuTreeByOrganizationId.apply(this, arguments);
}